package br.com.portalecbahia;

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import br.com.portalecbahia.dao.StadiumDAO;
import br.com.portalecbahia.model.Stadium;

import com.google.analytics.tracking.android.EasyTracker;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class StadiumMap extends MapActivity {
	   MapView mapView;
	   
	   private static final float MIN_ZOOM = 1.0f;
       private static final float MAX_ZOOM = 18f;//set Maximum zooming level
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.stadium_map);
	    
	    mapView = (MapView) findViewById(R.id.mapview);
	    mapView.setBuiltInZoomControls(true);
	    
		EasyTracker.getInstance().setContext(this);

	    
        Bundle loadInfo = getIntent().getExtras();
        String coordinate = (String) loadInfo.getSerializable("coordinate");
        String[] coordintates = coordinate.split("/");
        
        Float latCenter = new Float(coordintates[0]);
        Float lngCenter = new Float(coordintates[1]);
        
        GeoPoint point = new GeoPoint((int)(latCenter * 1E6), (int)(lngCenter * 1E6));

      
        mapView.getController().animateTo(point); 
        mapView.getController().setZoom(17); 
        
        List<Stadium> lStadium = new StadiumDAO(this).findAll();
        for (Stadium stadium : lStadium) {
        	List<Overlay> mapOverlays = mapView.getOverlays();
            Drawable drawable = this.getResources().getDrawable(R.drawable.stadium_icon);
            HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
            point = new GeoPoint((int)(new Float(stadium.getLatitude()) * 1E6), (int)(new Float(stadium.getLongitude())  * 1E6));
            OverlayItem overlayitem = new OverlayItem(point, stadium.getName(), stadium.getDescription());

            itemizedoverlay.addOverlay(overlayitem);
            mapOverlays.add(itemizedoverlay);
		}
        

        
        

	}
	
	 @Override
	    public void onStart() {
	      super.onStart();
	      EasyTracker.getInstance().activityStart(this); // Add this method.
	    }

	    @Override
	    public void onStop() {
	      super.onStop();
	      EasyTracker.getInstance().activityStop(this); // Add this method.
	    }
	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
	
	

}
